/*
 * Boton.java
 *
 * Created on 18 de marzo de 2008, 15:38
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package widget;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.InvocationTargetException;
import javax.swing.JButton;

/**
 *
 * @author notebook
 */
public class Boton extends JButton implements ActionListener{

    private Object objeto;

    private String metodo;
    
    /** Creates a new instance of Boton */
    public Boton(String nombre, int x, int y, int w, int h,Object obj, String met) {
        super(nombre);
        objeto = obj;
        metodo=met;
        setBounds(x,y,w,h);
        
        this.addActionListener(this);
    }

    public void actionPerformed(ActionEvent e) {
        try {
            objeto.getClass().getMethod(metodo,(Class[])null).invoke(objeto,(Object[])null);
        } catch (Exception ex) {
            System.out.println("boton:"+getText()+"\n"+objeto.getClass().getName()+"."+metodo+"()");
            ex.printStackTrace();
        }
    }
    
}
